package com.ycyun.admin.dao;

import com.ycyun.admin.model.SysUser;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

/**
 * @Author: 哦谢特谢特
 * @Date: 2018/5/18 14:33
 * @Description:
 */
@Mapper
public interface UserDao {
    @Options(useGeneratedKeys = true, keyProperty = "id")
    @Insert("insert into sys_user (username, password, nickname, avatar, phone, telephone, email, birthday, sex, status, createTime, updateTime) values(#{username}, #{password}, #{nickname}, #{avatar}, #{phone}, #{telephone}, #{email}, #{birthday}, #{sex}, #{status}, now(),now())")
    int save(SysUser user);

    @Select("select * from sys_user t where t.id = #{id}")
    SysUser getById(Long id);

    @Select("select * from sys_user t where t.username = #{username}")
    SysUser getUser(String username);

    @Update("update sys_user t set t.password = #{password} where t.id = #{id}")
    int changePassword(@Param("id") Long id, @Param("password") String password);

    Integer count(@Param("params") Map<String, Object> param);

    @Delete("delete from sys_role_user where userId = #{userId}")
    int deleteUserRole(Long userId);

    int saveUserRoles(@Param("userId") Long userId, @Param("roleIds") List<Long> roleIds);

    int update(SysUser user);

}
